using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace WaEvent.Generated
{
	/// <summary>
	/// Strongly-typed collection for the Follow class.
	/// </summary>
    [Serializable]
	public partial class FollowCollection : ActiveList<Follow, FollowCollection>
	{	   
		public FollowCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>FollowCollection</returns>
		public FollowCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Follow o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Follow table.
	/// </summary>
	[Serializable]
	public partial class Follow : ActiveRecord<Follow>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Follow()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Follow(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Follow(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Follow(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Follow", TableType.Table, DataService.GetInstance("WaEvent"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "Id";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarEventId = new TableSchema.TableColumn(schema);
				colvarEventId.ColumnName = "EventId";
				colvarEventId.DataType = DbType.Int32;
				colvarEventId.MaxLength = 0;
				colvarEventId.AutoIncrement = false;
				colvarEventId.IsNullable = true;
				colvarEventId.IsPrimaryKey = false;
				colvarEventId.IsForeignKey = true;
				colvarEventId.IsReadOnly = false;
				colvarEventId.DefaultSetting = @"";
				
					colvarEventId.ForeignKeyTableName = "iEvent";
				schema.Columns.Add(colvarEventId);
				
				TableSchema.TableColumn colvarFollowerName = new TableSchema.TableColumn(schema);
				colvarFollowerName.ColumnName = "FollowerName";
				colvarFollowerName.DataType = DbType.String;
				colvarFollowerName.MaxLength = 50;
				colvarFollowerName.AutoIncrement = false;
				colvarFollowerName.IsNullable = true;
				colvarFollowerName.IsPrimaryKey = false;
				colvarFollowerName.IsForeignKey = false;
				colvarFollowerName.IsReadOnly = false;
				colvarFollowerName.DefaultSetting = @"";
				colvarFollowerName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFollowerName);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarLastModifiedBy = new TableSchema.TableColumn(schema);
				colvarLastModifiedBy.ColumnName = "LastModifiedBy";
				colvarLastModifiedBy.DataType = DbType.String;
				colvarLastModifiedBy.MaxLength = 50;
				colvarLastModifiedBy.AutoIncrement = false;
				colvarLastModifiedBy.IsNullable = true;
				colvarLastModifiedBy.IsPrimaryKey = false;
				colvarLastModifiedBy.IsForeignKey = false;
				colvarLastModifiedBy.IsReadOnly = false;
				colvarLastModifiedBy.DefaultSetting = @"";
				colvarLastModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastModifiedBy);
				
				TableSchema.TableColumn colvarLastModifiedOn = new TableSchema.TableColumn(schema);
				colvarLastModifiedOn.ColumnName = "LastModifiedOn";
				colvarLastModifiedOn.DataType = DbType.DateTime;
				colvarLastModifiedOn.MaxLength = 0;
				colvarLastModifiedOn.AutoIncrement = false;
				colvarLastModifiedOn.IsNullable = true;
				colvarLastModifiedOn.IsPrimaryKey = false;
				colvarLastModifiedOn.IsForeignKey = false;
				colvarLastModifiedOn.IsReadOnly = false;
				colvarLastModifiedOn.DefaultSetting = @"";
				colvarLastModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastModifiedOn);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["WaEvent"].AddSchema("Follow",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("EventId")]
		[Bindable(true)]
		public int? EventId 
		{
			get { return GetColumnValue<int?>(Columns.EventId); }
			set { SetColumnValue(Columns.EventId, value); }
		}
		  
		[XmlAttribute("FollowerName")]
		[Bindable(true)]
		public string FollowerName 
		{
			get { return GetColumnValue<string>(Columns.FollowerName); }
			set { SetColumnValue(Columns.FollowerName, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		  
		[XmlAttribute("CreatedOn")]
		[Bindable(true)]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreatedOn); }
			set { SetColumnValue(Columns.CreatedOn, value); }
		}
		  
		[XmlAttribute("LastModifiedBy")]
		[Bindable(true)]
		public string LastModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.LastModifiedBy); }
			set { SetColumnValue(Columns.LastModifiedBy, value); }
		}
		  
		[XmlAttribute("LastModifiedOn")]
		[Bindable(true)]
		public DateTime? LastModifiedOn 
		{
			get { return GetColumnValue<DateTime?>(Columns.LastModifiedOn); }
			set { SetColumnValue(Columns.LastModifiedOn, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a IEvent ActiveRecord object related to this Follow
		/// 
		/// </summary>
		public WaEvent.Generated.IEvent IEvent
		{
			get { return WaEvent.Generated.IEvent.FetchByID(this.EventId); }
			set { SetColumnValue("EventId", value.Id); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varEventId,string varFollowerName,string varCreatedBy,DateTime? varCreatedOn,string varLastModifiedBy,DateTime? varLastModifiedOn)
		{
			Follow item = new Follow();
			
			item.EventId = varEventId;
			
			item.FollowerName = varFollowerName;
			
			item.CreatedBy = varCreatedBy;
			
			item.CreatedOn = varCreatedOn;
			
			item.LastModifiedBy = varLastModifiedBy;
			
			item.LastModifiedOn = varLastModifiedOn;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,int? varEventId,string varFollowerName,string varCreatedBy,DateTime? varCreatedOn,string varLastModifiedBy,DateTime? varLastModifiedOn)
		{
			Follow item = new Follow();
			
				item.Id = varId;
			
				item.EventId = varEventId;
			
				item.FollowerName = varFollowerName;
			
				item.CreatedBy = varCreatedBy;
			
				item.CreatedOn = varCreatedOn;
			
				item.LastModifiedBy = varLastModifiedBy;
			
				item.LastModifiedOn = varLastModifiedOn;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn EventIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn FollowerNameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn LastModifiedByColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn LastModifiedOnColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"Id";
			 public static string EventId = @"EventId";
			 public static string FollowerName = @"FollowerName";
			 public static string CreatedBy = @"CreatedBy";
			 public static string CreatedOn = @"CreatedOn";
			 public static string LastModifiedBy = @"LastModifiedBy";
			 public static string LastModifiedOn = @"LastModifiedOn";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
